package com.example.laboratory.ui.login;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.example.laboratory.R;
import com.example.laboratory.application.AppContext;
import com.example.laboratory.bean.User;
import com.example.laboratory.common.Const;
import com.example.laboratory.event.Event;
import com.example.laboratory.event.RxEvent;
import com.example.laboratory.manager.UserInfoManager;
import com.example.laboratory.root_ui.RMainActivity;
import com.example.laboratory.ui.base.BasePresenterActivity;
import com.example.laboratory.ui.main.MainActivity;
import com.example.laboratory.utils.LightStatusbarUtils;
import com.example.laboratory.utils.ToastUtils;


/**
 * 登录、注册
 * Created by 康栋普 on 2018/2/1.
 */

public class LoginActivity extends BasePresenterActivity<LoginPresenter> implements LoginContract.ILoginRegisterView {
    private EditText et_job_number, et_password;


    @Override
    public String getJobNumber() {
        return et_job_number.getText().toString().trim();
    }

    @Override
    public String getPassWord() {
        return et_password.getText().toString().trim();
    }

    @Override
    public void showResult(String msg) {
        ToastUtils.showToast(AppContext.getContext(), msg);
        RxEvent.getInstance().postEvent(Const.EVENT_ACTION.HOME, new Event(Event.Type.REFRESH_LIST));
        finish();
    }

    @Override
    public void showLoading(String msg) {
        showLoadingDialog(msg);
    }

    @Override
    protected LoginPresenter createPresenter() {
        return new LoginPresenter();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_login;
    }


    @Override
    protected void initViews() {
        et_job_number =  findViewById(R.id.et_username);
        et_password =  findViewById(R.id.et_password);
        findViewById(R.id.bt_login).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPresenter.login();
//                if (UserInfoManager.isLogin()) {
//
//                  User  user = UserInfoManager.getUserInfo();
//                    if(user.getPermission().equals("0")){
//                        Intent intent1 = new Intent(LoginActivity.super.getApplicationContext(), RMainActivity.class);
//                        startActivity(intent1);
//                        finish();
//
//                    }else{
//                        Intent intent2 = new Intent(LoginActivity.super.getApplicationContext(), MainActivity.class);
//                        startActivity(intent2);
//                        finish();
//                    }
//                }


            }
        });
        findViewById(R.id.bt_register).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPresenter.getDepartInfo();
            }
        });
    }

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        LightStatusbarUtils.setLightStatusBar(this, true);
    }


}
